<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
import { getAllAccountNum } from "@/api/media/echatData"
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 1500

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      datas:[]
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
   async initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      await getAllAccountNum({}).then((res)=>{
        this.datas = res.data
      });
     await this.chart.setOption(
        {
          title: {
            text: '平台账号分布概览',
            subtext: '账号数量',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '12%',
            left: 'center'
          },
          series: [
            {
              name: '平台账号分布概览',
              type: 'pie',
              radius: '30%',
              data: this.datas,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        })
    }
  }
}
</script>
